Welcome Guest | Sign in | Register

Home > C Programming > Preprocessor Directives > Questions and Answers

Exercise:

Section 1

01. What is the output of following C code?
#define a 10
main()
{
#define a 50
printf("%d",a);
}
A. 50 B. 10
C. 15 D. Error

Answer and Explanation

Answer: 50

Explanation:
The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What is the output of following C code?

#define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
A. 100 B. 200
C. Compiler Error D. null

Answer and Explanation

Answer: 100

Explanation:
Preprocessor executes as a separate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs. The input program to compiler looks like this :
main()
{
100;
printf("%d\n",100);
}
Note:
100; is an executable statement but with no action. So it doesn't give any problem

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. What is the output of following C code?
#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
A. 100 B. 12
C. 112 D. 0

Answer and Explanation

Answer: 100

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. What is the output of following C code?

#define FALSE -1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}
A. Error B. NULL
C. FALSE D. TRUE

Answer and Explanation

Answer: TRUE

Explanation:
Preprocessor doesn't replace the values given inside the double quotes. The check by if condition is boolean value false so it goes to else. In second if -1 is Boolean value true hence "TRUE" is printed.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. What is the output of following C code?
#if something == 0
int some=0;
#endif

main()
{
int thing = 0;
printf("%d %d\n", some ,thing);
}
A. 0 B. null
C. 0 0 D. error

Answer and Explanation

Answer: 0 0

Explanation:
This code is to show that preprocessor expressions are not the same as the ordinary expressions. If a name is not known the preprocessor treats it to be equal to zero.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What will be output if you will compile and execute the following c code?
01 #include
02 #define x 5+2
03 int main()
04 {
05 int i;
06 i=x*x*x;
07 printf("%d",i);
08 return 0;
09 }
A. 343 B. 27
C. 133 D. Compile Error
E. None of above

Answer and Explanation

Answer: 27

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. In which header file is the NULL macro defined?
A. stdio.h B. stddef.h
C. stdio.h and stddef.h D. Math.h

Answer and Explanation

Answer: stdio.h and stddef.h

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. What will be the result of the following code?
#define TRUE 0
while(TRUE)
{
printf(“Wipro-BITS”);
}
printf(“BITS PILANI”);
A. Wipro-BITS B. Nothing will be printed
C. BITS D. BITS PILANI

Answer and Explanation

Answer: BITS PILANI

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. Referring to the sample below, what is MAX_NUM?
#define MAX_NUM 15 
A. MAX_NUM is an integer variable. B. MAX_NUM is a linker constant.
C. MAX_NUM is a precompiler constant. D. MAX_NUM is a preprocessor macro.
E. MAX_NUM is an integer constant.

Answer and Explanation

Answer: MAX_NUM is a preprocessor macro.

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved 2012-2015 SoftLucent.